﻿using System.Collections.Generic;
using System;
using ANLP;
namespace Evaluant.NLinq
{
    //[System.Diagnostics.DebuggerNonUserCode]
    public partial class Lexer : ANLP.LexerBase
    {
        private static IDictionary<int, IDictionary<LexerHandler, TokenHandler>> expressions;

        static Lexer()
        {
            expressions = new Dictionary<int, IDictionary<LexerHandler, TokenHandler>>();
            IDictionary<ANLP.LexerHandler, ANLP.TokenHandler> normalExpressions = new Dictionary<ANLP.LexerHandler, ANLP.TokenHandler>();
            expressions.Add(0, normalExpressions);
            AddRegex(normalExpressions, "\\G[A-Za-z_@][A-Za-z0-9_]*", delegate() { return (int)Tokens.ID; });
            AddString(normalExpressions, "[", delegate() { return (int)Tokens.BracketOpen; });
            AddString(normalExpressions, "]", delegate() { return (int)Tokens.BracketClose; });
            AddString(normalExpressions, "{", delegate() { return (int)Tokens.BraceOpen; });
            AddString(normalExpressions, "}", delegate() { return (int)Tokens.BraceClose; });
            AddString(normalExpressions, "(", delegate() { return (int)Tokens.ParenthesisOpen; });
            AddString(normalExpressions, ")", delegate() { return (int)Tokens.ParenthesisClose; });
            AddString(normalExpressions, "?", delegate() { return (int)Tokens.QuestionMark; });
            AddString(normalExpressions, ":", delegate() { return (int)Tokens.Colon; });
            AddString(normalExpressions, "||", delegate() { return (int)Tokens.BooleanOr; });
            AddString(normalExpressions, "&&", delegate() { return (int)Tokens.BooleanAnd; });
            AddString(normalExpressions, "!=", delegate() { return (int)Tokens.NotEquals; });
            AddString(normalExpressions, "!", delegate() { return (int)Tokens.Not; });
            AddString(normalExpressions, ",", delegate() { return (int)Tokens.COMMA; });
            AddString(normalExpressions, "+", delegate() { return (int)Tokens.Plus; });
            AddString(normalExpressions, "-", delegate() { return (int)Tokens.Minus; });
            AddString(normalExpressions, "*", delegate() { return (int)Tokens.Multiply; });
            AddString(normalExpressions, "/", delegate() { return (int)Tokens.Divide; });
            AddString(normalExpressions, "%", delegate() { return (int)Tokens.Modulo; });
            AddString(normalExpressions, "==", delegate() { return (int)Tokens.Equals; });
            AddString(normalExpressions, "=>", delegate() { return (int)Tokens.Arrow; });
            AddString(normalExpressions, "<=", delegate() { return (int)Tokens.LessThanOrEquals; });
            AddString(normalExpressions, "<", delegate() { return (int)Tokens.LessThan; });
            AddString(normalExpressions, ">=", delegate() { return (int)Tokens.GreaterThanOrEquals; });
            AddString(normalExpressions, ">", delegate() { return (int)Tokens.GreaterThan; });
            AddString(normalExpressions, ".", delegate() { return (int)Tokens.Dot; });
            AddString(normalExpressions, "new", delegate() { return (int)Tokens.New; });
            AddString(normalExpressions, "=", delegate() { return (int)Tokens.Equal; });
            AddRegex(normalExpressions, "\\G[0-9]+", delegate() { return (int)Tokens.INTEGER; });
            AddRegex(normalExpressions, "\\G[0-9]*\\.[0-9]+", delegate() { return (int)Tokens.FLOAT; });
            AddRegex(normalExpressions, "\\G'([^\\\\']|\\\\[^']|\\\\')*'", delegate() { return (int)Tokens.STRING; });
            AddString(normalExpressions, "true", delegate() { return (int)Tokens.TRUE; });
            AddString(normalExpressions, "false", delegate() { return (int)Tokens.FALSE; });
            AddString(normalExpressions, "DateTime", delegate() { return (int)Tokens.DATETIME; });
            AddString(normalExpressions, "from", delegate() { return (int)Tokens.FROM; });
            AddString(normalExpressions, "in", delegate() { return (int)Tokens.IN; });
            AddString(normalExpressions, "into", delegate() { return (int)Tokens.INTO; });
            AddString(normalExpressions, "where", delegate() { return (int)Tokens.WHERE; });
            AddString(normalExpressions, "let", delegate() { return (int)Tokens.LET; });
            AddString(normalExpressions, "join", delegate() { return (int)Tokens.JOIN; });
            AddString(normalExpressions, "on", delegate() { return (int)Tokens.ON; });
            AddString(normalExpressions, "equals", delegate() { return (int)Tokens.EQUALS; });
            AddString(normalExpressions, "orderby", delegate() { return (int)Tokens.ORDERBY; });
            AddString(normalExpressions, "select", delegate() { return (int)Tokens.SELECT; });
            AddString(normalExpressions, "group", delegate() { return (int)Tokens.GROUP; });
            AddString(normalExpressions, "by", delegate() { return (int)Tokens.BY; });
            AddString(normalExpressions, "ascending", delegate() { return (int)Tokens.ASCENDING; });
            AddString(normalExpressions, "descending", delegate() { return (int)Tokens.DESCENDING; });
            AddRegex(normalExpressions, "\\G[ \\t\\n\\r\\f\\v]", delegate() { return (int)Tokens.Whitespace; });
        }

        protected override void Initialize()
        {
            base.lexExpressions = Lexer.expressions;
        }
    }
}
